//
//  ChangePasswordViewController.m
//  DigitalCampus
//
//  Created by 刘占宇 on 16/5/15.
//  Copyright © 2016年 刘占宇. All rights reserved.
//

#import "ChangePasswordViewController.h"
#import "LoginViewController.h"

@interface ChangePasswordViewController ()<UITextFieldDelegate>{
    NSString *jiumimaStr;
    NSString *xinmimaStr0;
    NSString *xinmimaStr1;
    NSMutableDictionary *Parameter_Dic;
}
@property (weak, nonatomic) IBOutlet UITextField *jiumima;
@property (weak, nonatomic) IBOutlet UITextField *xinmima0;
@property (weak, nonatomic) IBOutlet UITextField *xinmima1;

@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.jiumima.delegate = self;
    self.jiumima.tag = 1000;
    self.xinmima0.delegate = self;
    self.xinmima0.tag = 1001;
    self.xinmima1.delegate = self;
    self.xinmima1.tag = 1002;
}

- (NSString *)setNavTitle{
    return @"修改密码";
}

- (UIButton *)set_rightButton{
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 28, 20.5)];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font = AdaptedFontSize(12);
    return button;
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField.tag == 1000) {
        jiumimaStr = textField.text;
    }else if (textField.tag == 1001)
    {
        xinmimaStr0 = textField.text;
    }else if (textField.tag == 1002)
    {
        xinmimaStr1 = textField.text;
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

- (void)right_button_event:(UIButton *)sender{
    [self.view endEditing:YES];
    if (![NSString isEmpty:jiumimaStr] && ![NSString isEmpty:xinmimaStr0] && ![NSString isEmpty:xinmimaStr1]) {
        if ([jiumimaStr isEqualToString:[[User shareInstance] getPassWord]]) {
            if ([xinmimaStr0 isEqualToString:xinmimaStr1]) {
                [LZYNetworkHelper POST:editpwd parameters:@{@"oldPwd":jiumimaStr,@"newPwd":xinmimaStr0} success:^(id responseObject) {
                    [self.navigationController popViewControllerAnimated:YES];
                } failure:^(NSError *error) {
                    [LZYShowMsg showText:@"密码更新失败"];
                } showHub:YES];
            }else {
                [LZYShowMsg showText:@"两次新密码输入不一致"];
            }
        }else{
             [LZYShowMsg showText:@"旧密码输入错误"];
        }
    }else{
        [LZYShowMsg showText:@"密码不能为空"];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
